clear all
sigma = 1e5;
threshold = 200;
polygon_set1=[103 0
    246 0
    347 100
    347 245
    246 347
    103 347
    2 245
    2 100];
polygon_set1_part1=[
    246 347
    103 347
    2 245
    2 100];
polygon_set2=[422 0
    566 2
    667 102
    666 246
    567 347
    422 347
    322 246
    322 102];
polygon_set3=[395 3
    496 3
    327 73
    566 73
    326 173
    566 173
    394 242
    497 242];

polygon_set4 = [311 9
    434 79
    472 218
    401 344
    261 379
    138 309
    100 169
    172 46
    ];
 polygon_set4_part1= [311 9
    434 79
    472 218
    ];

 polygon_set5 =[100 1
     244 1
     344 46
     344 109
     244 153
     101 155
     1 110
     1 48];
  polygon_set6 =[290 85
      433 85
      535 130
      532 192
      434 237
      290 236
      188 193
      189 129
      ];
    polygon_set7 =[187 40
        296 51
        419 122
        486 211
        454 267
        344 254
        220 183
        156 94
     
      ];
  

set1 = polygon_set5';
set2 = polygon_set6';
% set2 = polygon_set2;
%计算质心
[len,c]=size(set1);
centroid_set1=[sum(set1(1,:))/len,sum(set1(2,:))/len]';
centroid_set2=[sum(set2(1,:))/len,sum(set2(2,:))/len]';

disp('质心1');disp(centroid_set1);
disp('质心2');disp(centroid_set2);
%点集减去质心
set1= set1-centroid_set1;
set2 = set2-centroid_set2;
disp('去质心点集1');disp(set1);
disp('去质心点集2');disp(set2);
%求 点集1中点*点集2重点转置
w=zeros(2,2);
for i=1:len
    w=w+set1(i,:)*set2(i,:)';
end

disp('w');disp(w);
disp('进行特征值分解');
[U,S,V]=svd(w);
R=U*V';
T=centroid_set1-R*centroid_set2;
disp('R');disp(R);
disp('T');disp(T);
